#include "CE.h"
#include "CE_SceneManager.h"

using namespace pugi;

CE_SINGLETON_INIT(CE_SceneManager);

CE_SceneManager::CE_SceneManager(void)
{
	m_startScene = NULL;
}

CE_SceneManager::~CE_SceneManager(void)
{
	clear();
}

void CE_SceneManager::clear()
{
	for(SceneVectorIt it = m_scenes.begin(); it!=m_scenes.end(); it++)
	{
		delete (*it);
	}
	m_scenes.clear();
	m_startScene = NULL;
}

bool CE_SceneManager::addScene(const char* sceneName, bool startScene)
{
	CE_Scene* newScene = new CE_Scene();
	newScene->setSceneName(sceneName);
	newScene->setStartScene(startScene);
	m_scenes.push_back(newScene);

	if(startScene)
		m_startScene = newScene;

	return true;
}

bool CE_SceneManager::setScenes(pugi::xpath_node_set sceneNodeSet)
{
	for(xpath_node_set::const_iterator it = sceneNodeSet.begin(); it!=sceneNodeSet.end(); it++)
	{
		xpath_node sceneNode = *it;
		this->addScene(
			sceneNode.node().attribute(CE_ATTR_NAME).value(),
			CE_Var::toBool(sceneNode.node().attribute(CE_ATTR_START_SCENE).value())
		);
	}

	return true;
}
